﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Net;
using System.Net.Sockets;
using System.IO;

namespace StuMana.UI
{
    public partial class test : Form
    {
        public test()
        {
            InitializeComponent();
        }
        public float hi= 0;
        public float wi =0;
        private void test_Load(object sender, EventArgs e)
        {
            hi = this.ClientSize.Height;
            wi= this.ClientSize.Width;
            MessageBox.Show(hi.ToString() +"-"+ wi.ToString());
        }

        private void test_Resize(object sender, EventArgs e)
        {
            float hiX=this.ClientSize.Height;
            float wiX=this.ClientSize.Width;
            foreach( Control con in this.Controls)
            {
                int x = 0,y=0,w=0,h=0;

                if(hiX > hi)
                {
                    y = con.Location.Y + ((int)(hiX-hi)/2);
                    h=con.Size.Height+ ((int)(hiX-hi)/2);
                }
                else if (hi > hiX)
                {
                    y = con.Location.Y - ((int)(hiX-hi)/2);
                    h = con.Size.Height -((int)(hiX-hi)/2);
                }

                
                if(wiX > wi)
                {
                    x = con.Location.X + ((int)(wiX-wi)/2);
                    w= con.Size.Width + ((int)(wiX-wi)/2);
                }
                else if (hi > hiX)
                {
                    x = con.Location.X - ((int)(wiX-wi)/2);
                    w=con.Size.Width -((int)(wiX-wi)/2);
                }
                
                con.Location = new Point(x,y);
                con.Size= new System.Drawing.Size(w,h);
                
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Socket sock = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);

            IPEndPoint iep = new IPEndPoint(IPAddress.Any, 30303);
            byte[] data = new byte[1024];
            string strData ="";
            StreamWriter sw = new StreamWriter("log.txt");
            sock.Bind(iep);
            sw.Flush();
            
                sock.Receive(data, data.Length, SocketFlags.None);
                strData = Encoding.Default.GetString(data);
                sw.WriteLine(strData);
                sw.Close();

               
           
            

        }
                 
      
         
    }
}
